package com.jeeplus.modules.monitor.task;

import com.alibaba.fastjson.JSONObject;
import com.jeeplus.modules.monitor.entity.ScheduleJob;
import com.jeeplus.modules.monitor.entity.Task;
import org.quartz.DisallowConcurrentExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.weixin4j.Weixin;

import java.lang.reflect.Method;
/***
 * 调用java内部方法
 *
 * @Author LH
 * @Description //TODO
 * @Date 14:26 2019/11/8
 * @return
 **/
@DisallowConcurrentExecution
public class JavaClassMothed extends Task {

	/**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(getClass());
    @Override
    @Scheduled(cron = "0/1 * * * * ? ") // 每隔1秒隔行一次
    public void run(ScheduleJob scheduleJob) {
        try {
        	String className="";
        	String methodName="";
			try {
				String remarks = scheduleJob.getRemarks().replaceAll("&quot;","\"");
				//System.out.println(remarks);
				JSONObject jsonObject=JSONObject.parseObject(remarks);
				className=jsonObject.getString("ClassName");
				methodName=jsonObject.getString("MethodName");
			}catch (Exception e){
				e.printStackTrace();
				logger.error("JSON数据解析失败");
			}
			Class<?> c = Class.forName(className);
			Object obj = c.newInstance();
			//类型 String paramClass = "java.lang.String";
			Method method = c.getDeclaredMethod(methodName, new Class[]{});
			//参数 String paramValue = "jack";
			method.invoke(obj, new Object[]{});
		}
        catch (Exception e)
		{
			e.printStackTrace();
		}
    }

}
